﻿{% extends "base.html" %}


{% block css %}
	<link rel = "stylesheet" href = "/css/home.css" type = "text/css" />
{% endblock %}

{% block javascript %}
	<script type = "text/javascript" src = "/js/jquery-1.6.2.js">
	</script>
	<script type = "text/javascript" src = "/js/ajax_post.js">
	</script>
	<script type = "text/javascript">
		$(document).ready(function()
		{
			var content = $("#blog_textarea").val();
			content = content.trim();
			var left_length = 140 - content.length;
			$(".counter").text(left_length);
			
			$("#blog_textarea").keyup(function()
			{
				var content = $("#blog_textarea").val();
				content = content.trim();
				var left_length = 140 - content.length;
				//alter(left_length);
				$(".counter").text(left_length);
				
				if(left_length < 0)
				{
					$(".counter").addClass("tiperror");
					$(".tip").css("color", "#C00");
				}
				else
				{
					$("#message .tip").removeClass("tiperror");
					$(".counter").removeClass("tiperror");
					$(".tip").css("color", "#CCC");
				}
			});
			
			$("#message").submit(function()
			{
				if($(".counter").text() < 0)
				{
					alert("微博长度超过140字，请调整长度!");
					return false;
				}
				return true;
			});
			$(".delete").click(function()
			{
				var result = confirm("确定要删除这条微博吗？");
				if(result == false)
					return result;
				else
				{
					jQuery.post("/delete/", { delete_post_id: $(this).children().first().text() },
					function(data)
					{
						if(data != "删除成功")
							alert(data);
					});
					$(this).parent().parent().remove();
				}
					
				return false;
			});
			
		});
	</script>
{% endblock %}



{% block title %}
Dlib-MicroBlog 首页
{% endblock %}

{% block navigationlist %}

	<ul>
		<li>
			<a href = "/home">首页</a>
		</li>
		<li>
			<a href = "/nick/{{ session_user.nick_name }}">我的空间</a>
		</li>
		
		<li>
			<a href = "/message">私信</a>
		</li>
		<li>
			<a href = "/finder">找人</a>
		</li>
		
		<li>
			<a href = "/browse">随便看看</a>
		</li>
		<li>
			<a href = "/search">搜索</a>
		</li>
		
		<li>
			<a href = "/settings">设置</a>
		</li>
		<li>
			<a href = "/logout">退出</a>
		</li>
		
	</ul>
	
{% endblock %}

{% block body %}
	<table id = "columns">
		<tr>
			<td id = "main">
				<div id = "update">
					<form method = "post" action ="{{ request_path }}" id = "message" class = "limit">
						<h2>你在做什么？</h2>
						<p class = "tip">
							可以输入
							<span class = "counter">
							</span>
							字
						</p>
						
						
						<textarea id = "blog_textarea" name = "content" rows = "3" cols = "70">{{ textarea_content }}</textarea>
						<div class = "lastmessage">
						</div>
						
						<div class = "submit_btn">
							<input id = "submit_btn" type = "submit" value = "发 布" />
						</div>
					</form>
				</div>
				<div id = "stream">
					<ol class = "dashtop">
						{% for blogpost in blogpost_list %}
							<li class = "unlight">
							
								<a href = "/nick/{{ blogpost.0.user.nick_name }}" class = "author">
									{{ blogpost.0.user.nick_name }}
								</a>
								<span class = "content">
									{{ blogpost.2|safe }}
								</span>
								<span class = "stamp">
									<a href = "/microblog/{{ blogpost.0.id }}">
									{{ blogpost.0.post_datetime|timesince }}前
									</a> &nbsp;通过网页
								</span>
							
								<span class = "op">
								{% if blogpost.1 %}
									<a href = "#" class = "delete"><span class = "deleteidspan">{{ blogpost.0.id }}</span></a>
								{% else %}
									<a href = "/home/reply/{{ blogpost.0.id }}" class = "reply">回复</a>
									<a href = "/home/forward/{{ blogpost.0.id }}" class = "forward">转发</a>
								{% endif %}
							
								</span>	
							</li>
						{% endfor %}
					
					</ol>
				</div>
				
			</td>
			<td id = "sidebar">
				<div id = "user_top">
				</div>
				
				<ul id = "reminder">
				</ul>
				
				<ul id = "user_stats">
					<li>
						<a href = "/follower">
							<span class = "count">{{ follower_count  }}</span>
							<span class = "label">我关注的人</span>
						</a>
					</li>
					<li>
						<a href = "/followee">
							<span class = "count">{{ fans_count  }}</span>
							<span class = "label">关注我的人</span>
						</a>
					</li>
					<li>
						<a href = "/nick/{{ session_user.nick_name }}">
							<span class = "count">{{ blog_count }}</span>
							<span class = "label">微博</span>
						</a>
					</li>
				</ul>
				
				<div class = "stabs" id = "navtabs">
					<ul>
						<li class ="current">
							<a href = "/home">
								<span class = "label">首页
								</span>
							</a>
						</li>
						<li>
							<a href = "/mention">
								<span class = "label">@提到我的
								</span>
							</a>
						</li>
						<li>
							<a href = "/message">
								<span class = "label">私信
								</span>
							</a>
						</li>
						
					</ul>
				</div>
				
				<div id = "search_bar">
					<form action = "/search" method = "post">
						<input type = "text" id = "search_input"  />
						<input type = "submit" id = "search_button" value = "搜索"/>
					</form>
				</div>
		
			</td>
		</tr>
	</table>
{% endblock %}
